import axios from 'axios';

import { axiosConfig } from '../env';

const apiClient = axios.create({ ...axiosConfig, timeout: 6000000 });

/**
 * 检查数据源账户可用性
 * @param {object} credentials - { username, password }
 * @returns Promise
 */
export const checkDataSource = (credentials) => {
    return apiClient.post('/v1/datasource/check-availability', credentials);
};

/**
 * 初始化基金主体信息
 * @param {object} data - { username, password, limit, fund_types }
 * @returns Promise
 */
export const initializeUniverse = (data) => {
    return apiClient.post('/v1/funds/initialize-universe', data);
};

/**
 * 批量初始化基金数据
 * @param {object} data - { mode, username, password, dataTypes, strategy }
 * @returns Promise
 */
export const batchInitializeData = (data) => {
    return apiClient.post('/v1/batch-collection/execute', data);
};

/**
 * 初始化基金公告
 * @returns Promise
 */
export const initializeAnnouncements = () => {
    return apiClient.post('/fund/ttjj/fetch/announcement/all');
};

/**
 * 初始化基金持仓
 * @returns Promise
 */
export const initializeHoldings = () => {
    return apiClient.post('/fund/ttjj/fetch/holding/all');
};

/**
 * 数据初始化相关API
 * baseUrl: /api
 */

/**
 * 检查数据源可用性（验证账号密码）
 * 对应接口：POST /api/auth/check
 * @param {Object} params - 请求参数
 * @param {string} params.account - 聚源账户用户名
 * @param {string} params.password - 聚源账户密码
 */
export const checkDataSourceAvailability_ = (params) => {
    return apiClient.post('/auth/check', params);
};

/**
 * 为基金主体自动提取标签
 * 对应接口：POST /api/tag/auto-assign
 */
export const extractTagsForUniverse_ = () => {
    return apiClient.post('/tag/auto-assign');
};